<template>
  <div class="audition215">
    <p>nextTick 和 setImmediate 都是延迟加载。</p>
    <p>nextTick 是放在当前队列的最后一个执行</p>
    <p>setImmediate 是在下一个队列的队首执行</p>
    <p>在node环境中运行如下代码:</p>
    <v-md-preview :text="text1" />
    <p>可以得到如下运行结果：</p>
    <code class="code">
      1 <br>
      3<br>
      'nextTick'<br>
      'setTimeout'<br>
      'setImmediate'<br>
      // <span class="color">*注</span>：最后面两个顺序是不一定的哦
    </code>
  </div>
</template>

<script>
const prefix = '``` js'
const suffix = '```'
export default {
  name: 'Audition215',
  data() {
    return {
      text1: `${prefix}
      console.log(1);
      //下一个队列的队首
      setImmediate(() => {
        console.log('setImmediate');
      });
      //放在setImmediate和nextTick中间
      setTimeout(() => {
        console.log('setTimeout')
      })
      //放在当前队列的最后一个
      process.nextTick(() => {
        console.log('nextTick');
      });
      console.log(3);
      \n${suffix}`,
    }
  }
}
</script>

<style>

</style>